<?php

namespace App\Admin\Controllers;

use App\Models\Order;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Order::with(['user', 'position.robot.pair.site']), function (Grid $grid) {
            $grid->fixColumns(4,-4);
            $grid->model()->orderBy('created_at', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.email', '用户邮箱');
            $grid->column('user.mobile', '用户手机号');
            $grid->column('position_id');
            $grid->column('position.robot.pair.site.site_name', '交易所');
            $grid->column('position.robot.pair.symbol', '交易对');
            $grid->column('side')->using(['buy'=>'买入', 'sell'=>'卖出']);
            $grid->column('number');
            $grid->column('price');
            $grid->column('fee');
            $grid->column('fee_coin');
            $grid->column('total');
            $grid->column('final_total');
            $grid->column('final_number');
            $grid->column('order_no');
            $grid->column('type')->using(['1'=> '首单','2'=>'系统补仓','3'=>'用户补仓','4'=>'系统卖出','5'=>'用户卖出']);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user.email', '用户邮箱');
                $filter->equal('user.mobile', '用户手机号');
                $filter->equal('position.robot.pair.site.site_name', '交易所');
                $filter->equal('position.robot.pair.symbol', '交易对');
                $filter->equal('order_no', '交易所订单号');
                $filter->equal('type')->select(['1'=> '首单','2'=>'系统补仓','3'=>'用户补仓','4'=>'系统卖出','5'=>'用户卖出']);
            });
            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
